<%--
  Created by IntelliJ IDEA.
  User: sai
  Date: 2019-03-26
  Time: 00:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    java.sql.Connection conn = null;
    java.lang.String strConn;
    java.sql.PreparedStatement preparedStmt = null; //语句对象
    java.sql.ResultSet sqlRst = null; //结果集对象
    try {
        conn = java.sql.DriverManager.getConnection("jdbc:h2:~/test_customer;MODE=MYSQL;DB_CLOSE_DELAY=-1", "sa", "");
        preparedStmt = conn.prepareStatement("select customerid,firstname,lastname,address from customer where firstname like ? ");
//设置参数
        String parm = request.getParameter("parm");
        preparedStmt.setString(1, "%" + parm + "%");
//执行sql语句
        sqlRst = preparedStmt.executeQuery();
%>
<center>顾客信息表</center>
<table border="1" width="100%" bordercolorlight="#CC99FF" cellpadding="2" bordercolordark="#FFFFFF" cellspacing="0">
    <tr>
        <td align="center">&nbsp;ID</td>
        <td align="center">地址</td>
        <td align="center">姓名</td>
    </tr>
    <% while (sqlRst.next()) { //取得下一条记录
        String name = sqlRst.getString("firstname");
        name += sqlRst.getString("lastname");
    %>
    <tr><!--显示记录-->
        <td><%=sqlRst.getString("customerid")%>
        </td>
        <td><%=sqlRst.getString("address")%>
        </td>
        <td><%=name%>
        </td>
    </tr>
    <% } %>
</table>
<%
    } catch (java.sql.SQLException e) {
        out.println(e.toString());
    } finally {
//关闭结果集对象
        if (sqlRst != null) try {
            sqlRst.close();
        } catch (java.sql.SQLException e1) {
            out.println(e1.toString());
        } finally {
            try {
//关闭语句对象
                if (preparedStmt != null) preparedStmt.close();
            } catch (java.sql.SQLException e2) {
                out.println(e2.toString());
            } finally {
                try {
//关闭数据库连接
                    if (conn != null) conn.close();
                } catch (java.sql.SQLException e3) {
                    out.println(e3.toString());
                }
            }
        }
    }
%>
</body>
</html>
